package com.appstore.service.impl;

import com.appstore.mapper.AppMapper;
import com.appstore.mapper.DownloadHistoryMapper;
import com.appstore.domain.entity.App;
import com.appstore.domain.entity.DownloadHistory;
import com.appstore.service.DownloadHistoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DownloadHistoryServiceImpl implements DownloadHistoryService {

    @Resource
    private DownloadHistoryMapper downloadHistoryMapper;
    @Resource
    private AppMapper appMapper;
    @Override
    public List<DownloadHistory> getDownloadHistoryByUserId(String userId) {

        return downloadHistoryMapper.getDownloadHistoryByUserId(userId);
    }

    @Override
    public Integer addDownloadHistory(DownloadHistory downloadHistory) {


        App app = appMapper.getAppById(downloadHistory.getAppId());
        downloadHistory.setAppName(app.getName());
        downloadHistory.setIconUrl(app.getIconUrl());
        return downloadHistoryMapper.addDownloadHistory(downloadHistory);
    }
}
